package com.guava.collection;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

import java.util.Iterator;
import java.util.Set;

/**
 * MultisetTester--GuavaTest
 *
 * @author: Jovi
 * @createTime: 2018-05-08 15:06
 **/
public class MultisetTester {

    public static void main(String[] args) {

        Multiset<String> multiset = HashMultiset.create();
        multiset.add("a");
        multiset.add("b");
        multiset.add("c");
        multiset.add("d");
        multiset.add("a");
        multiset.add("b");
        multiset.add("c");
        multiset.add("b");
        multiset.add("b");
        multiset.add("b");

        System.out.println("Occurrence of 'b' : " + multiset.count("b"));

        System.out.println("Totabl size : "+multiset.size());

        Set<String> set = multiset.elementSet();
        System.out.print("Set [ ");
        for (String s : set) {
            System.out.print(s+" ");
        }
        System.out.println("]");

        Iterator<String> iterator = multiset.iterator();
        System.out.print("MultiSet [ ");
        while (iterator.hasNext()) {
            System.out.print(iterator.next()+ " ");
        }
        System.out.println("]");

        System.out.print("MultiSet [ ");
        for (Multiset.Entry<String> stringEntry : multiset.entrySet()) {
            System.out.print("Element : "+ stringEntry.getElement() +", Occurrence : "+ stringEntry.getCount()+";");
        }
        System.out.println("]");

        multiset.remove("b", 2);
        System.out.println("Occurrence of 'b' : "+multiset.count("b"));
    }
}
